﻿#region [ License information          ]
/* ************************************************************
 *
 * Copyright (c) Bjørn Bouet Smith, 2012
 *
 * This source code is subject to terms and conditions of 
 * Microsoft Public License (Ms-PL).
 * 
 * A copy of the license can be found in the license.txt
 * file at the root of this distribution. If you can not 
 * locate the License, please send an email to bjornsmith@gmail.com
 * 
 * By using this source code in any fashion, you are 
 * agreeing to be bound by the terms of the Microsoft 
 * Public License.
 *
 * You must not remove this notice, or any other, from this
 * software.
 *
 * ************************************************************/
#endregion

using System.IO;

namespace Smith.BuildExtensions.ConfigurationTransformation
{
    /// <summary>
    /// Writes configuration files.
    /// </summary>
    public class ConfigWriter : IConfigWriter
    {
        private readonly string outputFileName;

        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigWriter"/> class.
        /// </summary>
        /// <param name="outputFileName">Name of the output file.</param>
        public ConfigWriter(string outputFileName)
        {
            this.outputFileName = outputFileName;
        }

        /// <summary>
        /// Writes the configuration to the output filename
        /// </summary>
        /// <param name="contents">The contents.</param>
        public void WriteConfiguration(string contents)
        {
            //TODO: We possibly have to fix line endings, I have seen weirdness where \r\n was converted into \n when using the File.WriteAllText
            // Write to output filePath
            File.WriteAllText(outputFileName, contents);
        }
    }
}
